from django.db import models
from django.contrib.auth.models import User

class Idc(models.Model):
    # 定义机房
   # owner = models.ForeignKey(User)  #机主
    name = models.CharField(max_length=50, verbose_name='机房名称')
    remark = models.CharField(max_length=50, verbose_name='备注')
    date_added = models.DateTimeField(auto_now_add=True)         #创建时间

    class Meta:
        verbose_name = '机房'
        verbose_name_plural = '机房'
    def __str__(self):
        #反回字符串name
        return self.name


class Ip(models.Model):
    #用ip做外键
    host = models.ForeignKey("Host")
    ip = models.GenericIPAddressField(verbose_name="ip")


class Host(models.Model):
    #定义主机列表
    idc = models.ForeignKey(Idc)
    date_added = models.DateTimeField(auto_now=True)
    hostname = models.CharField(max_length=50, verbose_name='主机名称')
    number = models.CharField(max_length=50, verbose_name='编号')
    application = models.CharField(max_length=50,verbose_name='应用')

    class Meta:
        verbose_name = '主机列表'
        verbose_name_plural = '主机列表'
        def __str__(self):
            return self.hostname


class HostInfo(models.Model):
    #定义主机信息
    host = models.ForeignKey(Host)
    manufacturer = models.CharField(max_length=50, verbose_name='厂商')
    productmode = models.CharField(max_length=50, verbose_name='产品型号')
    serialnumber = models.CharField(max_length=50, verbose_name='产品序列号')
    cpu = models.CharField(max_length=50, verbose_name='CPU核数')
    mem = models.CharField(max_length=50, verbose_name='内存')
    os = models.CharField(max_length=50, verbose_name='操作系统')
    disk = models.CharField(max_length=50, verbose_name='硬盘大小')
    class Meta:
        verbose_name = '主机信息'
        verbose_name_plural = '主机信息'
    def __str__(self):
        return self.host.hostname